<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 

<?php 
require "hrfuns.php"; 
Valid_Client();
?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Init Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head>
<body>
<?php
const DATADIR = "data";

if (isset($_POST["submit"])) {
    $iSQL = GetSQL(false);
    $iSQL->query("drop database nexan");

    $sqlstr = "";
    if ($file = fopen(DATADIR . "/hr_init.sql", "r")) {
        while ($line = fgets($file)) {
            $line = trim($line);
            if (strlen($line) == 0) continue;
            if ($line[0] == "#") continue;

            $sqlstr .= $line;

            if (substr($sqlstr, -1) == ";") {
                echo $sqlstr;
                $ret = $iSQL->query($sqlstr);
                if ($ret) echo " ... <font color=green>Pass</font><br />\n";
                else echo " ... <font color=red><bold>Failed</bold></font><br />\n";
                $sqlstr = "";
            }
            $sqlstr .= " ";
        }
    }
    echo "Done";
    $iSQL->close(); 
}
?>
</body>

